package com.kpf.springcloud.utils;

import com.kpf.springcloud.pojo.KpfTopic;

/**
 * 权重算法工具类
 *
 * @author shiwen
 * @date 2021/4/6
 */
public class SortUtils {

    /**
     * 计算当前帖子权重值
     *
     * @param kpfTopic
     * @return
     */
    public static Integer countSortNo(KpfTopic kpfTopic) {
        if (GeneralUtil.isObjNull(kpfTopic)) {
            return 0;
        }
        int likeWeight = kpfTopic.getLikeNum();
        int collectWeight = kpfTopic.getCollectNum();
        int commentWeight = kpfTopic.getCommentNum();
        int visitWeight = kpfTopic.getVisitNum();
        // 最终权重值 = 评论数 * 4 + 访问数 * 3 * 点赞数 * 2 + 收藏数
        int resultWeight = commentWeight * 4 + visitWeight * 3 + likeWeight * 2 + collectWeight;
        return resultWeight;
    }

}